<?php
	class Auth
	{
		function __construct($registry)
		{
			$this->registry = $registry;
		}

		private function encryptPassword($username, $password)
		{
			// Make a secured and encrypted password to sha512();

			return hash("sha512" ,$password.$username);
		}

		public function login($username, $password)
		{
			$password = $this->encryptPassword($username, $password);

			try
			{
				$stmt = $this->registry->db->prepare("
					SELECT 
						id 
					FROM 
						".DB_PREFIX."users 
					WHERE 
						username=:username AND 
						password=:password
					LIMIT
						1");
				$stmt->execute(array(
					':username'		=> $username,
					':password'		=> $password));
				if($stmt->fetch(PDO::FETCH_NUM) == 0)
				{
					$_SESSION['loggedin'] = false;
					return false;
				}
				else
				{
					// TODO: Load player group permissions in a session.
					$_SESSION['loggedin'] = true;
					return true;
				}
			}
			catch(Exception $e)
			{
				echo $e;
				exit();
			}
		}

		public function isLoggedin()
		{
			if($_SESSION['loggedin'] === true)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		public function isAllowed($action)
		{
			if($this->isLoggedin())
			{
				//$
			}
		}
	}
?>